import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

import { ApiService, JsonResult } from './api.service';
import { EmailListVo, AddVo, EditVo, SendVo,  ReceiverListVo, ReceiverVo } from 'src/app/shared/models';




@Injectable({
  providedIn: 'root'
})
export class EmailService {

  constructor(private apiService: ApiService) { }

  getEmailConfig() {
    return this.apiService.get('/data/email/config')
      .pipe(
        map((jsonResult: JsonResult<EmailListVo>) => jsonResult)
      );
  }
  // 添加邮件模板配置
  addEmailConfig(info: any) {
    return this.apiService.post('/data/email/config', info)
      .pipe(
        map((jsonResult: JsonResult<AddVo>) => jsonResult)
      );
  }
  // 修改邮件模板配置
  editEmailConfig(info: any) {
    return this.apiService.put('/data/email/config', info).pipe(
      map((jsonResult: JsonResult<EditVo>) => jsonResult)
    );
  }
  // 发送邮件接口
  sendEmail(info: any) {
    return this.apiService.post('/data/email/sending', info).pipe(map((jsonResult: JsonResult<SendVo>) => jsonResult));
  }
  // 获取企业收件人列表（企业收件人下来列表）
  getReceiverList() {
    return this.apiService.get('/data/email/getorglist').pipe(
      map((jsonResult: JsonResult<ReceiverVo>) =>  jsonResult ));
        // console.log('list', jsonResult);
  }
}
